﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.WXT.Domain;
using System.WXT.Domain.DTO;
using System.WXT.Infrstructre.Impl;
using System.WXT.Infrstructre.Interface;
using System.WXT.WebAPI.Application.Command.WorkerCommand;

namespace System.WXT.WebAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WorkeController : ControllerBase
    {
        protected readonly IMediator mediator;

        public WorkeController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 工人添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPost]
        public async Task<ApiResult<int>> WorkeAdd(WorkerAddCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 工人显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ApiResult<PageDTO<Worker>>> WorkeShow([FromQuery]WorkerShowCommand command)
        {
            ApiResult<PageDTO<Worker>> result = new ApiResult<PageDTO<Worker>>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 工人删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ApiResult<int>> WorkeDelete(WorkerDeleteCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 工人反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ApiResult<Worker>> WorkeBackFill([FromQuery]WorkerBackFillCommand command)
        {
            ApiResult<Worker> result = new ApiResult<Worker>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 工人修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ApiResult<int>> WorkeUpdate(WorkerUpdateCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        ///// <summary>
        ///// 工人修改状态
        ///// </summary>
        ///// <param name = "request" ></ param >
        ///// < param name="cancellationToken"></param>
        ///// <returns></returns>
        ///// 
        ////[HttpPost]
        ////public async Task<ApiResult<int>> Handle()
        ////{

        ////}
    }
}
